package gui.VPOfOperations;

import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;

import javax.swing.border.TitledBorder;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;

import org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;
import org.jdatepicker.impl.UtilDateModel;

import utilities.DateLabelFormatter;
import entities.RequestParameters;
import gui.engraving.EngravingFrame;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;

import javax.swing.DefaultComboBoxModel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JRadioButton;

import java.awt.SystemColor;
import java.awt.Font;

/**
 * @author Idan
 * GUI for report creation.
 * Generates reports according to parameters given by the user using predetermined formats.
 */
public class VPOfOperationsReports extends JPanel
{
	
	public static int reportCounter = 1;
	private UtilDateModel startDate;
	private UtilDateModel endDate;

	private VPOfOperationsReports myself;
	private VPOfOperationsTabbedPackagingReport myPackagingReport;
	private JComboBox endDiopterComboBox;
	private JComboBox startDiopterComboBox;
	private JComboBox familyComboBox;
	private VPOfOperationsTabbedPane myTabbedPane;
	private VPOfOperationsTabbedPolishReport myPolishReport;
	private JDatePickerImpl datePickerstart;
	private JDatePickerImpl datePickerend;
	private VPOfOperationsTabbedEngraveReport myEngraveReport;
	private VPOfOperationsTabbedQCReport myQCReport;
	private VPOfOperationsTabbedHashmashaReport myHashmashaReport;
	private VPOfOperationsTabbedDiscardReport myDiscardReport;
	private ButtonGroup group;
	private static ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/report.png"));
	
	
	public VPOfOperationsReports(VPOfOperationsTabbedPane myTabbedPane)
	{
		setBackground(new Color(173, 216, 230));
		this.myTabbedPane = myTabbedPane;
		this.myself = this;
		
		
		UtilDateModel startmodel = new UtilDateModel();
		UtilDateModel endmodel = new UtilDateModel();
		
		
		Properties p = new Properties();
		p.put("text.today", "היום");
		p.put("text.month", "חודש");
		p.put("text.year", "שנה");
		JDatePanelImpl startPanel = new JDatePanelImpl(startmodel, p);
		JDatePanelImpl endPanel = new JDatePanelImpl(endmodel, p);
		

		datePickerstart = new JDatePickerImpl(startPanel, new DateLabelFormatter());
		datePickerstart.getJFormattedTextField().setFont(new Font("Tahoma", Font.PLAIN, 13));
		datePickerstart.setBackground(new Color(173, 216, 230));
		datePickerstart.getJFormattedTextField().setBackground(SystemColor.inactiveCaption);
		datePickerstart.getJFormattedTextField().setHorizontalAlignment(SwingConstants.CENTER);
		datePickerend = new JDatePickerImpl(endPanel, new DateLabelFormatter());
		datePickerend.getJFormattedTextField().setFont(new Font("Tahoma", Font.PLAIN, 13));
		datePickerend.setBackground(new Color(173, 216, 230));
		datePickerend.getJFormattedTextField().setBackground(SystemColor.inactiveCaption);
		datePickerend.getJFormattedTextField().setHorizontalAlignment(SwingConstants.CENTER);
		
		
		
		// set first day of the month the default start date
		
		startmodel.setDate(startmodel.getYear(), startmodel.getMonth(), 1);
				
		startDate = startmodel;
		endDate = endmodel;
		
		
	
		
		setLayout(new MigLayout("", "[grow][][grow]", "[grow][][][grow]"));
		
		JPanel panel = new JPanel(){	@Override
			public void paintComponent(Graphics g) {
	        Graphics2D g2d = (Graphics2D) g;
	        Color color1 = getBackground();
	        Color color2 = color1.darker();
	        int w = getWidth();
	        int h = getHeight(); 
	        GradientPaint gp = new GradientPaint(
	                0, 0, color1,
	                0, h, color2);

	        g2d.setPaint(gp);
	        g2d.fillRect(0, 0, w, h);
	        }};
		panel.setBackground(new Color(173, 216, 230));
		panel.setBorder(new TitledBorder(null, "\u05D3\u05D5\u05D7\u05D5\u05EA", TitledBorder.RIGHT, TitledBorder.TOP, null, new Color(59, 59, 59)));
		add(panel, "cell 1 1,growx,aligny center");
		panel.setLayout(new MigLayout("", "[][grow][]", "[][][][][]"));
		
		JPanel panel_1 = new JPanel(){	@Override
			public void paintComponent(Graphics g) {
	        Graphics2D g2d = (Graphics2D) g;
	        Color color1 = getBackground();
	        Color color2 = color1.darker();
	        int w = getWidth();
	        int h = getHeight(); 
	        GradientPaint gp = new GradientPaint(
	                0, 0, color1,
	                0, h, color2);

	        g2d.setPaint(gp);
	        g2d.fillRect(0, 0, w, h);
	        }};
		panel_1.setBackground(new Color(173, 216, 230));
		panel_1.setBorder(new TitledBorder(null, "\u05E4\u05E8\u05DE\u05D8\u05E8\u05D9\u05DD \u05DC\u05D3\u05D5\u05D7", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panel.add(panel_1, "cell 1 1,grow");
		panel_1.setLayout(new MigLayout("", "[grow][][][][][grow]", "[::50px,grow][][][][][][][::50px,grow]"));
		
		JLabel label_2 = new JLabel("טווח תאריכים:");
		label_2.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_1.add(label_2, "cell 4 1");

		panel_1.add(datePickerend, "cell 1 2,alignx right");

		
		JLabel label_1 = new JLabel("עד ל-");
		panel_1.add(label_1, "cell 2 2,alignx trailing");
		
		;
		panel_1.add(datePickerstart, "cell 3 2,alignx right");
		
		
		startmodel.setSelected(true);
		endmodel.setSelected(true);
		
		JLabel label = new JLabel("החל מ-");
		label.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_1.add(label, "cell 4 2,alignx right");
		
		JLabel label_3 = new JLabel("טווח דיופטרים:");
		label_3.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_1.add(label_3, "cell 4 3");
		
		endDiopterComboBox = new JComboBox();
		endDiopterComboBox.setFont(new Font("Tahoma", Font.PLAIN, 13));
		endDiopterComboBox.setModel(new DefaultComboBoxModel(new String[] {"0.0" , "1.0" , "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "8.5", "9.0", "9.5", "10.0", "10.5", "11.0", "11.5", "12.0", "12.5", "13.0", "13.5", "14.0", "14.5", "15.0", "15.5", "16.0", "16.5", "17.0", "17.5", "18.0", "18.5", "19.0", "19.5", "20.0", "20.5", "21.0", "21.5", "22.0", "22.5", "23.0", "23.5", "24.0", "24.5", "25.0", "25.5", "26.0", "26.5", "27.0", "27.5", "28.0", "28.5", "29.0", "29.5", "30.0", "30.5", "31.0", "32.0", "33.0", "34.0", "35.0", "36.0", "37.0", "38.0", "39.0", "40.0"}));
		endDiopterComboBox.setPreferredSize(new Dimension(50, 20));
		panel_1.add(endDiopterComboBox, "cell 1 4,alignx right");
		
		JLabel label_5 = new JLabel("עד ל-");
		panel_1.add(label_5, "cell 2 4,alignx right");
		
		startDiopterComboBox = new JComboBox();
		startDiopterComboBox.setFont(new Font("Tahoma", Font.PLAIN, 13));
		startDiopterComboBox.setModel(new DefaultComboBoxModel(new String[] {"0.0" , "1.0" , "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "8.5", "9.0", "9.5", "10.0", "10.5", "11.0", "11.5", "12.0", "12.5", "13.0", "13.5", "14.0", "14.5", "15.0", "15.5", "16.0", "16.5", "17.0", "17.5", "18.0", "18.5", "19.0", "19.5", "20.0", "20.5", "21.0", "21.5", "22.0", "22.5", "23.0", "23.5", "24.0", "24.5", "25.0", "25.5", "26.0", "26.5", "27.0", "27.5", "28.0", "28.5", "29.0", "29.5", "30.0", "30.5", "31.0", "32.0", "33.0", "34.0", "35.0", "36.0", "37.0", "38.0", "39.0", "40.0"}));
		startDiopterComboBox.setPreferredSize(new Dimension(50, 20));
		panel_1.add(startDiopterComboBox, "cell 3 4,alignx right");
		
		JLabel label_4 = new JLabel("החל מ-");
		label_4.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_1.add(label_4, "cell 4 4,alignx right");
		
		JLabel label_6 = new JLabel("משפחת מוצרים:");
		label_6.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_1.add(label_6, "cell 4 5,alignx right");
		
		familyComboBox = new JComboBox();
		familyComboBox.setFont(new Font("Tahoma", Font.PLAIN, 13));
		familyComboBox.setModel(new DefaultComboBoxModel(new String[] {"הכל", "הידרופיליות", "הידרופוביות", "PMMA", "פרסביה"}));
		((JLabel)familyComboBox.getRenderer()).setHorizontalAlignment(JLabel.RIGHT);
		panel_1.add(familyComboBox, "cell 3 6,alignx right");

		
		JLabel label_7 = new JLabel("בחר משפחה:");
		label_7.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_1.add(label_7, "cell 4 6,alignx right");
		
		JPanel panel_2 = new JPanel(){	@Override
			public void paintComponent(Graphics g) {
	        Graphics2D g2d = (Graphics2D) g;
	        Color color1 = getBackground();
	        Color color2 = color1.darker();
	        int w = getWidth();
	        int h = getHeight(); 
	        GradientPaint gp = new GradientPaint(
	                0, 0, color1,
	                0, h, color2);

	        g2d.setPaint(gp);
	        g2d.fillRect(0, 0, w, h);
	        }};
		panel_2.setBackground(new Color(173, 216, 230));
		panel_2.setBorder(new TitledBorder(null, "\u05E1\u05D5\u05D2 \u05D3\u05D5\u05D7", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panel.add(panel_2, "cell 1 2,grow");
		panel_2.setLayout(new MigLayout("", "[grow][grow][grow]", "[::50px,grow][grow][grow][grow][::50px,grow]"));
		
		JPanel panel_3 = new JPanel(){	@Override
			public void paintComponent(Graphics g) {
	        Graphics2D g2d = (Graphics2D) g;
	        Color color1 = getBackground();
	        Color color2 = color1.darker();
	        int w = getWidth();
	        int h = getHeight(); 
	        GradientPaint gp = new GradientPaint(
	                0, 0, color1,
	                0, h, color2);

	        g2d.setPaint(gp);
	        g2d.fillRect(0, 0, w, h);
	        }};
		panel_3.setBackground(new Color(173, 216, 230));
		panel_3.setBorder(new TitledBorder(null, "\u05E4\u05E1\u05D9\u05DC\u05D5\u05EA", TitledBorder.RIGHT, TitledBorder.TOP, null, null));
		panel_2.add(panel_3, "cell 1 1,grow");
		panel_3.setLayout(new MigLayout("", "[grow][][][][grow]", "[grow][][][][][grow]"));
		
		JRadioButton failQuantitiesByReasonRadioButton = new JRadioButton("דוח פסילות על פי סיבה");
		failQuantitiesByReasonRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		failQuantitiesByReasonRadioButton.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_3.add(failQuantitiesByReasonRadioButton, "cell 1 1,alignx right");
		
		JRadioButton failQuantitiesByMonthEngraveRadioButton = new JRadioButton("דוח פסילות על פי חודש ייצור");
		failQuantitiesByMonthEngraveRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		failQuantitiesByMonthEngraveRadioButton.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_3.add(failQuantitiesByMonthEngraveRadioButton, "cell 2 1,alignx right");
		
		JRadioButton failPercentageradioButtonR = new JRadioButton("דוח אחוזי פסילות");
		failPercentageradioButtonR.setFont(new Font("Tahoma", Font.PLAIN, 13));
		failPercentageradioButtonR.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_3.add(failPercentageradioButtonR, "flowx,cell 3 1,alignx right");
		
		JRadioButton failQuantitiesByLineRadioButton = new JRadioButton("דוח פסילות על פי קו");
		failQuantitiesByLineRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		failQuantitiesByLineRadioButton.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_3.add(failQuantitiesByLineRadioButton, "cell 1 2,alignx right");
		
		JRadioButton failQuantitiesByMonthQCRadioButton = new JRadioButton("דוח פיסלות על פי חודש בדיקה");
		failQuantitiesByMonthQCRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		failQuantitiesByMonthQCRadioButton.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_3.add(failQuantitiesByMonthQCRadioButton, "cell 2 2,alignx right");
		
		JRadioButton failQuantitiesRadioButton = new JRadioButton("דוח פסילות כמותי");
		failQuantitiesRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		failQuantitiesRadioButton.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_3.add(failQuantitiesRadioButton, "flowx,cell 3 2,alignx right");
		
		JRadioButton failQuantitiesByTimeQCRadioButton = new JRadioButton("דוח פסילות על ציר הזמן (בדיקה)");
		failQuantitiesByTimeQCRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		failQuantitiesByTimeQCRadioButton.setHorizontalAlignment(SwingConstants.RIGHT);
		panel_3.add(failQuantitiesByTimeQCRadioButton, "cell 1 3,alignx right");
		
		JPanel panel_4 = new JPanel(){	@Override
			public void paintComponent(Graphics g) {
	        Graphics2D g2d = (Graphics2D) g;
	        Color color1 = getBackground();
	        Color color2 = color1.darker();
	        int w = getWidth();
	        int h = getHeight(); 
	        GradientPaint gp = new GradientPaint(
	                0, 0, color1,
	                0, h, color2);

	        g2d.setPaint(gp);
	        g2d.fillRect(0, 0, w, h);
	        }};
		panel_4.setBackground(new Color(173, 216, 230));
		panel_4.setBorder(new TitledBorder(null, "\u05E2\u05D5\u05D1\u05D3\u05D9\u05DD", TitledBorder.RIGHT, TitledBorder.TOP, null, null));
		panel_2.add(panel_4, "cell 1 2,grow");
		panel_4.setLayout(new MigLayout("", "[grow][][][][grow]", "[grow][][grow]"));
		
		JRadioButton employeeYieldsRadioButton = new JRadioButton("דוח ביצועי עובדים");
		employeeYieldsRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_4.add(employeeYieldsRadioButton, "cell 1 1");
		
		JRadioButton failQuantitiesByEmpoyeeRadioButton = new JRadioButton("דוח פסילות על פי עובד");
		failQuantitiesByEmpoyeeRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_4.add(failQuantitiesByEmpoyeeRadioButton, "cell 2 1");
		
		JPanel panel_5 = new JPanel(){	@Override
			public void paintComponent(Graphics g) {
	        Graphics2D g2d = (Graphics2D) g;
	        Color color1 = getBackground();
	        Color color2 = color1.darker();
	        int w = getWidth();
	        int h = getHeight(); 
	        GradientPaint gp = new GradientPaint(
	                0, 0, color1,
	                0, h, color2);

	        g2d.setPaint(gp);
	        g2d.fillRect(0, 0, w, h);
	        }};
		panel_5.setBackground(new Color(173, 216, 230));
		panel_5.setBorder(new TitledBorder(null, "\u05D3\u05D9\u05D5\u05D5\u05D7\u05D9\u05DD", TitledBorder.RIGHT, TitledBorder.TOP, null, null));
		panel_2.add(panel_5, "cell 1 3,grow");
		panel_5.setLayout(new MigLayout("", "[grow][][][][][grow]", "[][][][][][]"));
		
		JRadioButton packagingRadioButton = new JRadioButton("דוחות אריזה");
		packagingRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_5.add(packagingRadioButton, "cell 1 1,alignx center");
		
		
		JRadioButton qCRadioButton = new JRadioButton("דוחות בקרת איכות");
		qCRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_5.add(qCRadioButton, "cell 2 1,alignx center");
		
		JRadioButton polishRadioButton = new JRadioButton("דוחות ליטוש");
		polishRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_5.add(polishRadioButton, "cell 3 1,alignx center");

		JRadioButton engraveReportRadioButton = new JRadioButton("דוחות ייצור");
		engraveReportRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		panel_5.add(engraveReportRadioButton, "cell 4 1,alignx center");
		
		JButton exitButton = new JButton("יציאה מהמערכת");
		exitButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		exitButton.setIcon(new ImageIcon(VPOfOperationsReports.class.getResource("/graphics/exit.png")));
		exitButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0)
			{
				Object[] options = {"כן","לא"};
        		int n = JOptionPane.showOptionDialog(myself, "האם ברצונך לצאת מהמערכת?","אישור יציאה", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,"");
        		
        		if (n==0)
        		{
        			if (VPOfOperationsMain.voopClient != null)
                    {
                      try
                      {
                    	  VPOfOperationsMain.voopClient.close();
                      }
                      catch (Exception ignore)
                      {}
                     }
            		
            		System.exit(0);
        		}
        		
			}
		});
		add(exitButton, "cell 1 2,alignx center");
		endDiopterComboBox.setSelectedIndex(63);
		
		JButton createReportButton = new JButton("צור דוח");
		createReportButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		createReportButton.setIcon(new ImageIcon(VPOfOperationsReports.class.getResource("/graphics/createReport.png")));
		createReportButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0)
			{
				createReport();
			}
		});
		panel.add(createReportButton, "cell 1 3,alignx center");
		 
		
		JRadioButton rawMaterialRadioButton = new JRadioButton("דוח פסילה לאצוות חומר גלם");
		rawMaterialRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		 panel_3.add(rawMaterialRadioButton, "cell 2 3,alignx right");
		 JRadioButton failQuantitiesByTimeEngraveRadioButton = new JRadioButton("דוח פסילות על ציר הזמן (ייצור)");
		 failQuantitiesByTimeEngraveRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		 failQuantitiesByTimeEngraveRadioButton.setHorizontalAlignment(SwingConstants.RIGHT);
		 panel_3.add(failQuantitiesByTimeEngraveRadioButton, "cell 3 3,alignx right");
		 
		 JRadioButton excelRadioButton = new JRadioButton("דוח אקסל עבור כל בסיס הנתונים");
 		 excelRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
 		 panel_5.add(excelRadioButton, "cell 2 2,alignx center");
 		 
		failPercentageradioButtonR.setSelected(true);
		
		failPercentageradioButtonR.setActionCommand("getFailPercentageReport");
		failPercentageradioButtonR.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesRadioButton.setActionCommand("getFailQuantityReport");
		failQuantitiesRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesByMonthEngraveRadioButton.setActionCommand("getFailQuantitiesByEngraveMonth");
		failQuantitiesByMonthEngraveRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesByMonthQCRadioButton.setActionCommand("getFailQuantitiesByQCMonth");
		failQuantitiesByMonthQCRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesByReasonRadioButton.setActionCommand("getFailQuantitiesByReason");
		failQuantitiesByReasonRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesByLineRadioButton.setActionCommand("getFailQuantitiesByLine");
		failQuantitiesByLineRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesByTimeQCRadioButton.setActionCommand("getFailPercentagesByTimeQCReport");
		failQuantitiesByTimeQCRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		employeeYieldsRadioButton.setActionCommand("getEngraveQuantityByEmployeeReport");
		employeeYieldsRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesByEmpoyeeRadioButton.setActionCommand("getFailQuantityByEmployeeReport");
		failQuantitiesByEmpoyeeRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		engraveReportRadioButton.setActionCommand("createEngraveReport");
		engraveReportRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		polishRadioButton.setActionCommand("createPolishReport");
		polishRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		qCRadioButton.setActionCommand("createQCRepoort");
		qCRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		packagingRadioButton.setActionCommand("createPackagingReport");
		packagingRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		failQuantitiesByTimeEngraveRadioButton.setActionCommand("getFailPercentagesByTimeEngraveReport");
		failQuantitiesByTimeEngraveRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		rawMaterialRadioButton.setActionCommand("getRawMaterialsReport");
		rawMaterialRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		
		 excelRadioButton.setActionCommand("largeTableToExcel");
 		 excelRadioButton.setHorizontalTextPosition(SwingConstants.LEFT);

 		 
 		 
 		 //failPercentageradioButtonR
 		
		 
		 
		// Group buttons together
		 group = new ButtonGroup();
		 
		 group.add(failPercentageradioButtonR);
		 group.add(failQuantitiesRadioButton);
		 group.add(failQuantitiesByMonthEngraveRadioButton);
		 group.add(failQuantitiesByMonthQCRadioButton);
		 group.add(failQuantitiesByReasonRadioButton);
		 group.add(failQuantitiesByLineRadioButton);
		 group.add(failQuantitiesByTimeQCRadioButton);
		 group.add(rawMaterialRadioButton);
		 group.add(failQuantitiesByTimeEngraveRadioButton);
		 group.add(employeeYieldsRadioButton);
		 group.add(failQuantitiesByEmpoyeeRadioButton);
		 group.add(engraveReportRadioButton);
		 group.add(polishRadioButton);
		 group.add(qCRadioButton);
		 group.add(packagingRadioButton);
		 group.add(excelRadioButton);
		 		
		 
	
		 
		 
		 
		 JRadioButton productionDistributionBySubFamilyRadioButton = new JRadioButton("דוח התפלגות ייצור לפי תת-משפחה");
		 productionDistributionBySubFamilyRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		 panel_5.add(productionDistributionBySubFamilyRadioButton, "cell 3 2");
		 
		 productionDistributionBySubFamilyRadioButton.setActionCommand("getQuantitiesBySubFamilyReport");
		 productionDistributionBySubFamilyRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		 group.add(productionDistributionBySubFamilyRadioButton);
		 
		 JRadioButton productionDistributionByProductRadioButton = new JRadioButton("דוח התפלגות ייצור על פי מוצר");
		 productionDistributionByProductRadioButton.setFont(new Font("Tahoma", Font.PLAIN, 13));
		 panel_5.add(productionDistributionByProductRadioButton, "cell 4 2");
		 
		 productionDistributionByProductRadioButton.setActionCommand("getQuantitiesByProductReport");
		 productionDistributionByProductRadioButton.setHorizontalTextPosition(SwingConstants.LEFT); 
		 group.add(productionDistributionByProductRadioButton);
		 group.add(rawMaterialRadioButton);
		 
		 
	}
	
	
	protected void getQuantitiesByProductReport()
	{
		// get data
				ArrayList<Object> message = new ArrayList<Object>();
				
				message.add("getQuantitiesByProductReport");
						
				RequestParameters parameters= getReportParameters();
					
				message.add(parameters);
							
				try
				{
					ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
					if (response.size() == 0)
					{
					// connection error
					JOptionPane.showMessageDialog(myself,
							"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
						{
						// SQL Error
							JOptionPane.showMessageDialog(myself,
								    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
						}
						else
						{ 
							if (response.get(0).toString().equalsIgnoreCase("Empty"))
							{
								// empty report
								JOptionPane.showMessageDialog(myself,
									    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
							}
							else
							{
								// create report
								
								VPOfOperationsQuantitiesByProductReport report = new VPOfOperationsQuantitiesByProductReport(myTabbedPane, parameters);
								report.setVariables(response);
									
								 
								
								// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
								myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
										
								// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
								myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
								reportCounter++;
							}
						}
					}
					
									
								
					}
					catch (Exception e) 
					{
						
						//e.printStackTrace();
					}
		
	}

	protected void getFailPercentagesByTimeQCReport()
	{
		// get data
		ArrayList<Object> message = new ArrayList<Object>();
		
		message.add("getFailPercentagesByTimeQCReport");
				
		RequestParameters parameters= getReportParameters();
			
		message.add(parameters);
					
		try
		{
			ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
			if (response.size() == 0)
			{
			// connection error
			JOptionPane.showMessageDialog(myself,
					"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
				{
				// SQL Error
					JOptionPane.showMessageDialog(myself,
						    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
				}
				else
				{ 
					if (response.get(0).toString().equalsIgnoreCase("Empty"))
					{
						// empty report
						JOptionPane.showMessageDialog(myself,
							    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
					}
					else
					{
						// create report
						
						VPOfOperationsFailPercentageByTimeQCReport report = new VPOfOperationsFailPercentageByTimeQCReport(myTabbedPane, parameters);
						report.setVariables(response);
							
					//	ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
						
						// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
						myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
								
						// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
						myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
						reportCounter++;
					}
				}
			}
			
							
						
			}
			catch (Exception e) 
			{
				
				//e.printStackTrace();
			}
		
	}

	protected void getFailPercentagesByTimeEngraveReport()
	{
		// get data
				ArrayList<Object> message = new ArrayList<Object>();
				
				message.add("getFailPercentagesByTimeEngraveReport");
						
				RequestParameters parameters= getReportParameters();
					
				message.add(parameters);
							
				try
				{
					ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
					if (response.size() == 0)
					{
					// connection error
					JOptionPane.showMessageDialog(myself,
							"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
						{
						// SQL Error
							JOptionPane.showMessageDialog(myself,
								    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
						}
						else
						{ 
							if (response.get(0).toString().equalsIgnoreCase("Empty"))
							{
								// empty report
								JOptionPane.showMessageDialog(myself,
									    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
							}
							else
							{
								// create report
								
								VPOfOperationsFailPercentageByTimeEngraveReport report = new VPOfOperationsFailPercentageByTimeEngraveReport(myTabbedPane, parameters);
								report.setVariables(response);
									
								//ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
								
								// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
								myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
										
								// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
								myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
								reportCounter++;
							}
						}
					}
					
									
								
					}
					catch (Exception e) 
					{
						
						//e.printStackTrace();
					}
		
	}

	protected void getFailQuantityByEmployeeReport()
	{
		// get data
		ArrayList<Object> message = new ArrayList<Object>();
		
		message.add("getFailQuantityByEmployeeReport");
				
		RequestParameters parameters= getReportParameters();
			
		message.add(parameters);
					
		try
		{
			ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
			if (response.size() == 0)
			{
			// connection error
			JOptionPane.showMessageDialog(myself,
					"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
				{
				// SQL Error
					JOptionPane.showMessageDialog(myself,
						    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
				}
				else
				{ 
					if (response.get(0).toString().equalsIgnoreCase("Empty"))
					{
						// empty report
						JOptionPane.showMessageDialog(myself,
							    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
					}
					else
					{
						// create report
						
						VPOfOperationsFailQuantitiesByEmployeeReport report = new VPOfOperationsFailQuantitiesByEmployeeReport(myTabbedPane, parameters);
						report.setVariables(response);
							
						
						
						// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
						myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
								
						// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
						myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
						reportCounter++;
					}
				}
			}
			
							
						
			}
			catch (Exception e) 
			{
				
				//e.printStackTrace();
			}

		
	}

	protected void getEngraveQuantityByEmployeeReport()
	{
		// get data
				ArrayList<Object> message = new ArrayList<Object>();
				
				message.add("getEngraveQuantityByEmployeeReport");
						
				RequestParameters parameters= getReportParameters();
					
				message.add(parameters);
							
				try
				{
					ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
					if (response.size() == 0)
					{
					// connection error
					JOptionPane.showMessageDialog(myself,
							"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
						{
						// SQL Error
							JOptionPane.showMessageDialog(myself,
								    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
						}
						else
						{ 
							if (response.get(0).toString().equalsIgnoreCase("Empty"))
							{
								// empty report
								JOptionPane.showMessageDialog(myself,
									    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
							}
							else
							{
								// create report
								
								VPOfOperationsEngraveQuantitiesByEmployeeReport report = new VPOfOperationsEngraveQuantitiesByEmployeeReport(myTabbedPane, parameters);
								report.setVariables(response);
									
								//ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
								
								// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
								myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
										
								// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
								myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
								reportCounter++;
							}
						}
					}
					
									
								
					}
					catch (Exception e) 
					{
						
						//e.printStackTrace();
					}
		
	}

	protected void getFailQuantitiesByLine() 
	{
		// get data
		ArrayList<Object> message = new ArrayList<Object>();
		
		message.add("getFailQuantitiesByLine");
				
		RequestParameters parameters= getReportParameters();
			
		message.add(parameters);
					
		try
		{
			ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
			if (response.size() == 0)
			{
			// connection error
			JOptionPane.showMessageDialog(myself,
					"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
				{
				// SQL Error
					JOptionPane.showMessageDialog(myself,
						    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
				}
				else
				{ 
					if (response.get(0).toString().equalsIgnoreCase("Empty"))
					{
						// empty report
						JOptionPane.showMessageDialog(myself,
							    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
					}
					else
					{
						// create report
						
						VPOfOperationsFailQuantitiesByLineReport report = new VPOfOperationsFailQuantitiesByLineReport(myTabbedPane, parameters);
						report.setVariables(response);
							
						
						
						// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
						myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
								
						// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
						myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
						reportCounter++;
					}
				}
			}
			
							
						
			}
			catch (Exception e) 
			{
				
				//e.printStackTrace();
			}
		
	}

	protected void getFailQuantitiesByReason() 
	{
		// get data
				ArrayList<Object> message = new ArrayList<Object>();
				
				message.add("getFailQuantitiesByReason");
						
				RequestParameters parameters= getReportParameters();
					
				message.add(parameters);
							
				try
				{
					ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
					if (response.size() == 0)
					{
					// connection error
					JOptionPane.showMessageDialog(myself,
							"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
						{
						// SQL Error
							JOptionPane.showMessageDialog(myself,
								    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
						}
						else
						{ 
							if (response.get(0).toString().equalsIgnoreCase("Empty"))
							{
								// empty report
								JOptionPane.showMessageDialog(myself,
									    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
							}
							else
							{
								// create report
								
								VPOfOperationsFailQuantitiesByReasonReport report = new VPOfOperationsFailQuantitiesByReasonReport(myTabbedPane, parameters);
								report.setVariables(response);
									
								//ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
								
								// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
								myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
										
								// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
								myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
								reportCounter++;
							}
						}
					}
					
									
								
					}
					catch (Exception e) 
					{
						
						//e.printStackTrace();
					}
		
	}

	protected void getFailQuantitiesByQCMonth()
	{
		
		// get data
		ArrayList<Object> message = new ArrayList<Object>();
		
		message.add("getFailQuantitiesByQCMonth");
				
		RequestParameters parameters= getReportParameters();
			
		message.add(parameters);
					
		try
		{
			ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
			if (response.size() == 0)
			{
			// connection error
			JOptionPane.showMessageDialog(myself,
					"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
				{
				// SQL Error
					JOptionPane.showMessageDialog(myself,
						    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
				}
				else
				{ 
					if (response.get(0).toString().equalsIgnoreCase("Empty"))
					{
						// empty report
						JOptionPane.showMessageDialog(myself,
							    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
					}
					else
					{
						// create report
						VPOfOperationsFailQuantitiesByQCMonthReport report = new VPOfOperationsFailQuantitiesByQCMonthReport(myTabbedPane, parameters);
						report.setVariables(response);
							
					//	ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
						
						// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
						myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
								
						// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
						myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
						reportCounter++;
					}
				}
			}
			
							
						
			}
			catch (Exception e) 
			{
				
				//e.printStackTrace();
			}
		
	}

	protected void getFailQuantitiesByEngraveMonth() 
	{
		// get data
			ArrayList<Object> message = new ArrayList<Object>();
			
			message.add("getFailQuantitiesByEngraveMonth");
		
			RequestParameters parameters= getReportParameters();
			
			message.add(parameters);
			
			try
			{
			ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
			if (response.size() == 0)
			{
				// connection error
				JOptionPane.showMessageDialog(myself,
					    "ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
				{
					// SQL Error
					JOptionPane.showMessageDialog(myself,
						    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
				}
				else
				{ 
					if (response.get(0).toString().equalsIgnoreCase("Empty"))
					{
						// empty report
						JOptionPane.showMessageDialog(myself,
							    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
					}
					else
					{
						// create report
						VPOfOperationsFailQuantitiesByEngraveMonthReport report = new VPOfOperationsFailQuantitiesByEngraveMonthReport(myTabbedPane, parameters);
						report.setVariables(response);
						
						//ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
						
						// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
						myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
						
						// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
						myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
						reportCounter++;
						}
				}
			}
				
					
				
			}
			catch (Exception e) 
			{
				
				//e.printStackTrace();
			}		
	}

	protected void getFailPercentageReport() 
	{
		
		
		// get data
				ArrayList<Object> message = new ArrayList<Object>();
				
				message.add("getFailPercentagesReport");
			
				RequestParameters parameters= getReportParameters();
				
				message.add(parameters);
				
				try
				{
				ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
				if (response.size() == 0)
				{
					// connection error
					JOptionPane.showMessageDialog(myself,
						    "ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
				}
				else
				{
					if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
					{
						// SQL Error
						JOptionPane.showMessageDialog(myself,
							    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
					}
					else
					{ 
						if (response.get(0).toString().equalsIgnoreCase("Empty"))
						{
							// empty report
							JOptionPane.showMessageDialog(myself,
								    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
						}
						else
						{
							// create report
							VPOfOperationsFailPercentagesReport report = new VPOfOperationsFailPercentagesReport(myTabbedPane, parameters);
							report.setVariables(response);
							
							
							
							// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
							myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
							
							// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
							myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
							reportCounter++;

						}
					}
				}
					
					
				
				}
				catch (Exception e) 
				{
					
					//e.printStackTrace();
				}
				
				
		
	}

	protected void getFailQuantityReport() 
	{
		// get data
		ArrayList<Object> message = new ArrayList<Object>();
		
		message.add("getFailQuantityReport");
	
		RequestParameters parameters= getReportParameters();
		
		message.add(parameters);
		
		try
		{
		ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
		if (response.size() == 0)
		{
			// connection error
			JOptionPane.showMessageDialog(myself,
				    "ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
		}
		else
		{
			if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
			{
				// SQL Error
				JOptionPane.showMessageDialog(myself,
					    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			else
			{ 
				if (response.get(0).toString().equalsIgnoreCase("Empty"))
				{
					// empty report
					JOptionPane.showMessageDialog(myself,
						    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
				}
				else
				{
					// create report
					VPOfOperationsFailQuantitiesReport report = new VPOfOperationsFailQuantitiesReport(myTabbedPane, parameters);
					report.setVariables(response);
					
			
					
					// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
					myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
					
					// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
					myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
					reportCounter++;

				}
			}
		}
			
			
		
		}
		catch (Exception e) 
		{
			
			//e.printStackTrace();
		}
		
		
		
	}
	
	/**
	 * Read parameters for the report as chosen by the user
	 */

	private RequestParameters getReportParameters()
	{
		RequestParameters parameters = new RequestParameters();
		
		
		// handle dates
		
		Timestamp startTimestamp = new Timestamp ( startDate.getValue().getTime() );
		Timestamp endTimestamp = new Timestamp ( endDate.getValue().getTime() );
		
		if (startTimestamp.before(endTimestamp))
		{
			parameters.setStartTimestamp(startTimestamp);
			parameters.setEndTimestamp(endTimestamp);
		}
		else
		{
			parameters.setStartTimestamp(endTimestamp);
			parameters.setEndTimestamp(startTimestamp);
		}
		
		// handle diopters
		
		String startDiopter = startDiopterComboBox.getSelectedItem().toString();
		String endDiopter = endDiopterComboBox.getSelectedItem().toString();
		
		Float startDiopterFloat = Float.parseFloat(startDiopter);
		Float endDiopterFloat = Float.parseFloat(endDiopter);
		
		if (startDiopterFloat <= endDiopterFloat )
		{
			parameters.setStartDiopter(startDiopter);
			parameters.setEndDiopter(endDiopter);
		}
		else
		{
			parameters.setStartDiopter(endDiopter);
			parameters.setEndDiopter(startDiopter);
		}

		parameters.setFamily(familyComboBox.getSelectedItem().toString());
		
	
		return parameters;
		
		
	}
	
	/**
	 * create polish report
	 */
	private void createPolishReport() {
		String startDiopter = startDiopterComboBox.getSelectedItem().toString();
		String endDiopter = endDiopterComboBox.getSelectedItem().toString();

		Float startDiopterFloat = Float.parseFloat(startDiopter);
		Float endDiopterFloat = Float.parseFloat(endDiopter);
		
		String startDate = datePickerstart.getJFormattedTextField().getText().toString();
		String endDate = datePickerend.getJFormattedTextField().getText().toString();
		String family = familyComboBox.getSelectedItem().toString();
		
		//ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
		myPolishReport = new VPOfOperationsTabbedPolishReport(myTabbedPane,myself,startDiopterFloat,endDiopterFloat,startDate,endDate,family);
		if(myPolishReport.isEmpty==false)
		{
			myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, myPolishReport);
			
			// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
			myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
			reportCounter++;
		}
	}

	/**
	 * create engrave report
	 */
	private void createEngraveReport()
	{
		String startDiopter = startDiopterComboBox.getSelectedItem().toString();
		String endDiopter = endDiopterComboBox.getSelectedItem().toString();
		
		Float startDiopterFloat = Float.parseFloat(startDiopter);
		Float endDiopterFloat = Float.parseFloat(endDiopter);
		
		String startDate = datePickerstart.getJFormattedTextField().getText().toString();
		String endDate = datePickerend.getJFormattedTextField().getText().toString();
		String family = familyComboBox.getSelectedItem().toString();
		
		
		
		myEngraveReport = new VPOfOperationsTabbedEngraveReport(myTabbedPane,myself,startDiopterFloat,endDiopterFloat,startDate,endDate,family);
		if(myEngraveReport.isEmpty==false)
		{
			myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, myEngraveReport);
			// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
			myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
			reportCounter++;
		}
	}
	
	/**
	 * create quality report
	 */
	private void createQCRepoort()
	{
		
		String startDiopter = startDiopterComboBox.getSelectedItem().toString();
		String endDiopter = endDiopterComboBox.getSelectedItem().toString();
		
		Float startDiopterFloat = Float.parseFloat(startDiopter);
		Float endDiopterFloat = Float.parseFloat(endDiopter);
		
		String startDate = datePickerstart.getJFormattedTextField().getText().toString();
		String endDate = datePickerend.getJFormattedTextField().getText().toString();
		String family = familyComboBox.getSelectedItem().toString();
		
	//	ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
		
		myQCReport = new VPOfOperationsTabbedQCReport(myTabbedPane,myself,startDiopterFloat,endDiopterFloat,startDate,endDate,family);
		if(myQCReport.isEmpty==false)
		{
			myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, myQCReport);
			// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
			myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
			reportCounter++;
		}
	}
	
	/**
	 * Create report
	 * the report type is deduced by the marked JRadio Button
	 */
	private void createReport()
	{
		
		if (datePickerend.getJFormattedTextField().getText().equals("") || datePickerstart.getJFormattedTextField().getText().equals(""))
			{
				JOptionPane.showMessageDialog(myTabbedPane,
					    "טווח תאריכים שנבחר אינו תקין.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
		else
			{

					String execute = group.getSelection().getActionCommand();
					
					
					
					switch (execute)
					{
						case ("getFailPercentageReport"):
						{
							getFailPercentageReport();
							break;
						}
						case ("getFailQuantityReport"):
						{
							getFailQuantityReport();
							break;
						}
							
						case ("getFailPercentagesByTimeEngraveReport"):
						{		
							getFailPercentagesByTimeEngraveReport();
							break;
						}
						case ("getFailQuantitiesByEngraveMonth"):
						{
							getFailQuantitiesByEngraveMonth();
							break;
						}
						case ("getFailQuantitiesByQCMonth"):
						{
							getFailQuantitiesByQCMonth();
							break;
						}
						case ("getFailQuantitiesByReason"):
						{
							getFailQuantitiesByReason();
							break;
						}
						case ("getFailQuantitiesByLine"):
						{
							getFailQuantitiesByLine();
							break;
						}
						case ("getFailPercentagesByTimeQCReport"):
						{
							getFailPercentagesByTimeQCReport();
							break;
						}
						case ("getEngraveQuantityByEmployeeReport"):
						{
							getEngraveQuantityByEmployeeReport();
							break;
						}
						case ("getFailQuantityByEmployeeReport"):
						{
							getFailQuantityByEmployeeReport();
							break;
						}
						case ("getQuantitiesByProductReport"):
						{
							getQuantitiesByProductReport();
							break;
						}
						case ("getQuantitiesBySubFamilyReport"):
						{
							getQuantitiesBySubFamilyReport();
							break;
						}
						case ("createEngraveReport"):
						{
							createEngraveReport();
							break;
						}
						case ("createPolishReport"):
						{
							createPolishReport();
							break;
						}
						case ("createQCRepoort"):
						{
							createQCRepoort();
							break;
						}
						case ("getRawMaterialsReport"):
						{
							getRawMaterialsReport();
							break;
						}
						case ("createPackagingReport"):
						{
							createPackagingReport();
							creatingHashmashaReport();
							creatingDiscardReport();
							break;
						}
						case ("largeTableToExcel"):
						{
							Object[] options = {"כן","לא"};
			        		int n = JOptionPane.showOptionDialog(myself, "פעולה זו עלולה לקחת זמן רב, במהלכו המערכת לא תהיה זמינה." + "\n" +"יש לוודא כי קיימת תקיית היעד כפי שמוגדרת וכי היא ריקה מדוחות קודמים." + "\n" + "האם הנך בטוח?","אישור בקשה", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,"");
			        		
			        		if (n==0)
			        		{
			        			largeExcelTable();
			        		}
							
							break;
						}
						
						default:
							break;

					}
		
		}
			
	}


	/**
	 * Creates excel reports in the format used before the switch to the system
	 */
	private void largeExcelTable() 
	{
		
		ArrayList<Object> message = new ArrayList<Object>();
		message.add("largeTableToExcel");
		
		Properties prop = new Properties();
		//String propFileName = "./config/config.properties";
		String propFileName = "./config.properties";
		 
		InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
		 
		if (inputStream != null)
		{
			try
			{
				prop.load(inputStream);
				
				
				  
				String from = prop.getProperty("excel_from_date");
				String to = prop.getProperty("excel_to_date");
				String path = prop.getProperty("excel_folder_path");
				
		
						
				message.add(from);
				message.add(to);
				message.add(path);
				
				try
				{
					ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
					if (response.size() == 0)
					{
					// connection error
					JOptionPane.showMessageDialog(myself,
							"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						if (response.get(0).toString().equalsIgnoreCase("valid"))
						{
							JOptionPane.showMessageDialog(myself,
									"הדוח הופק בהצלחה.","אישור",JOptionPane.INFORMATION_MESSAGE);
						}
						else
						{
							JOptionPane.showMessageDialog(myself,
									"ארעה שגיאה ביצירת הדוח.","שגיאה",JOptionPane.ERROR_MESSAGE);
						}
					}
				}
				
				catch (Exception e) 
				{
				
					//e.printStackTrace();
					JOptionPane.showMessageDialog(myself,
							"ארעה שגיאה בעת יצירת הקובץ." + "\n" + "יש לוודא כי תקיית היעד קיימת וריקה מדוחות קודמים בעלי שם דומה.","שגיאה",JOptionPane.ERROR_MESSAGE);
					
				}
				
			} 
			catch (IOException e)
			{
			
				//e.printStackTrace();
				JOptionPane.showMessageDialog(myTabbedPane,
					    "הגדרות עבור קובץ האקסל אינן תקינות או חסרות.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			
			
		}
		else
		{
			JOptionPane.showMessageDialog(myTabbedPane,
				    "לא ניתן לקרוא את קובץ ההגדרות.","שגיאה",JOptionPane.ERROR_MESSAGE);
		}
		
	}

/**
 * Creates a report for raw materials used
 */
	private void getRawMaterialsReport()
	{
		// get data
				ArrayList<Object> message = new ArrayList<Object>();
				
				message.add("getRawMaterialsReport");
						
				RequestParameters parameters= getReportParameters();
					
				message.add(parameters);
							
				try
				{
					ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
					if (response.size() == 0)
					{
					// connection error
					JOptionPane.showMessageDialog(myself,
							"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
					}
					else
					{
						if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
						{
						// SQL Error
							JOptionPane.showMessageDialog(myself,
								    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
						}
						else
						{ 
							if (response.get(0).toString().equalsIgnoreCase("Empty"))
							{
								// empty report
								JOptionPane.showMessageDialog(myself,
									    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
							}
							else
							{
								// create report
								
								VPOfOperationsRawMaterialsReport report = new VPOfOperationsRawMaterialsReport(myTabbedPane, parameters);
								report.setVariables(response);
									
							
								
								// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
								myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
										
								// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
								myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
								reportCounter++;
							}
						}
					}
					
									
								
					}
					catch (Exception e) 
					{
					
						//e.printStackTrace();
					}
		
	}

	/**
	 * fails by subfamily report
	 */

	private void getQuantitiesBySubFamilyReport()
	{
		// get data
		ArrayList<Object> message = new ArrayList<Object>();
		
		message.add("getQuantitiesBySubFamilyReport");
				
		RequestParameters parameters= getReportParameters();
			
		message.add(parameters);
					
		try
		{
			ArrayList<Object> response = VPOfOperationsMain.voopClient.call(message);
			if (response.size() == 0)
			{
			// connection error
			JOptionPane.showMessageDialog(myself,
					"ארעה שגיאה בחיבור לשרת.","שגיאה",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				if (response.get(0).toString().equalsIgnoreCase("SQL Error"))
				{
				// SQL Error
					JOptionPane.showMessageDialog(myself,
						    "ארעה שגיאה בבסיס הנתונים.","שגיאה",JOptionPane.ERROR_MESSAGE);
				}
				else
				{ 
					if (response.get(0).toString().equalsIgnoreCase("Empty"))
					{
						// empty report
						JOptionPane.showMessageDialog(myself,
							    "אין נתונים המתאימים לפרמטרים שנבחרו.","אישור",JOptionPane.INFORMATION_MESSAGE);
					}
					else
					{
						// create report
						
						VPOfOperationsQuantitiesBySubFamilyReport report = new VPOfOperationsQuantitiesBySubFamilyReport(myTabbedPane, parameters);
						report.setVariables(response);
							
				
						
						// tabbed pane -> add tab, with a close button and string name = "Report " + reportCounter
						myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, report);
								
						// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
						myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
						reportCounter++;
					}
				}
			}
			
							
						
			}
			catch (Exception e) 
			{
				
				//e.printStackTrace();
			}
		
	}
	
	/**
	 * Package report
	 */
	private void createPackagingReport()
	{
		String startDiopter = startDiopterComboBox.getSelectedItem().toString();
		String endDiopter = endDiopterComboBox.getSelectedItem().toString();
		
		Float startDiopterFloat = Float.parseFloat(startDiopter);
		Float endDiopterFloat = Float.parseFloat(endDiopter);
		
		String startDate = datePickerstart.getJFormattedTextField().getText().toString();
		String endDate = datePickerend.getJFormattedTextField().getText().toString();
		String family = familyComboBox.getSelectedItem().toString();
		
	//	ImageIcon reportIcon = new ImageIcon(EngravingFrame.class.getResource("/graphics/new.png"));
		
		myPackagingReport = new VPOfOperationsTabbedPackagingReport(myTabbedPane,myself,startDiopterFloat,endDiopterFloat,startDate,endDate,family);
		if(myPackagingReport.isEmpty==false)
		{
			myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, myPackagingReport);
			// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
			myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
			reportCounter++;
		}
	}
	/**
	 * hashmasha report
	 */
	public void creatingHashmashaReport()
	{
		String startDiopter = startDiopterComboBox.getSelectedItem().toString();
		String endDiopter = endDiopterComboBox.getSelectedItem().toString();
		
		Float startDiopterFloat = Float.parseFloat(startDiopter);
		Float endDiopterFloat = Float.parseFloat(endDiopter);
		
		String startDate = datePickerstart.getJFormattedTextField().getText().toString();
		String endDate = datePickerend.getJFormattedTextField().getText().toString();
		String family = familyComboBox.getSelectedItem().toString();
		
	
		
		myHashmashaReport = new VPOfOperationsTabbedHashmashaReport(myTabbedPane,myself,startDiopterFloat,endDiopterFloat,startDate,endDate,family);
		if(myHashmashaReport.isEmpty==false)
		{
			myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, myHashmashaReport);
			// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
			myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
			reportCounter++;
		}
	}
	/**
	 * Discard report
	 */
	public void creatingDiscardReport()
	{
		String startDiopter = startDiopterComboBox.getSelectedItem().toString();
		String endDiopter = endDiopterComboBox.getSelectedItem().toString();
		
		Float startDiopterFloat = Float.parseFloat(startDiopter);
		Float endDiopterFloat = Float.parseFloat(endDiopter);
		
		String startDate = datePickerstart.getJFormattedTextField().getText().toString();
		String endDate = datePickerend.getJFormattedTextField().getText().toString();
		String family = familyComboBox.getSelectedItem().toString();
		
	
		
		myDiscardReport = new VPOfOperationsTabbedDiscardReport(myTabbedPane,myself,startDiopterFloat,endDiopterFloat,startDate,endDate,family);
		if(myDiscardReport.isEmpty==false)
		{
			myTabbedPane.addTab(" דוח " + reportCounter, reportIcon, myDiscardReport);
			// tabbed pane -> set selected index to the new report using indexOfTab("Report " + reportCounter)
			myTabbedPane.setSelectedIndex(myTabbedPane.getTabCount()-1);
		}
	}
	
	@Override
	public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    Color color1 = getBackground();
    Color color2 = color1.darker();
    int w = getWidth();
    int h = getHeight(); 
    GradientPaint gp = new GradientPaint(
            0, 0, color1,
            0, h, color2);

    g2d.setPaint(gp);
    g2d.fillRect(0, 0, w, h);
    }
}
	